package com.nervenets.web.hibernate.domain.film;

import com.nervenets.web.enumeration.MovieReleaseStatus;
import com.nervenets.web.enumeration.MovieStatus;
import com.nervenets.web.enumeration.MovieType;
import com.nervenets.web.hibernate.DomainObject;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.Type;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.util.ArrayList;
import java.util.List;

@Entity
@Table(name = "movies")
@EqualsAndHashCode(callSuper = true)
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Movie extends DomainObject {
    private long userId;//用户ID
    private long totalOfMoney;//筹集金额
    @Column(columnDefinition = "tinyint")
    private MovieType type;//影片类型
    @Column(columnDefinition = "tinyint")
    private MovieStatus status = MovieStatus.preheating;//影片状态
    @Column(columnDefinition = "tinyint")
    private MovieReleaseStatus releaseStatus = MovieReleaseStatus.planing;//影片发布状态
    @Type(type = "com.nervenets.web.adapter.jsonType.MovieInfoJson")
    private MovieInfo info = new MovieInfo();//影片信息
    @Type(type = "com.nervenets.web.adapter.jsonType.MovieCheckInfoJson")
    private MovieCheckInfo checkInfo;//影片审核信息
    @Type(type = "com.nervenets.web.adapter.jsonType.MovieCheckChangeJson")
    private List<MovieCheckChange> checkChanges = new ArrayList<>();
    private int disable;//禁用时间，0就是没有禁用
    private int queue;//排序值，值越大越靠前

    public String getTitle() {
        return !info.isValid() ? (null == checkInfo ? null : checkInfo.getTitle()) : info.getTitle();
    }

    public String getCoverImage() {
        return !info.isValid() ? (null == checkInfo ? null : checkInfo.getCoverImage()) : info.getCoverImage();
    }

    public long getPriceOfUnit() {
        return !info.isValid() ? (null == checkInfo ? 0L : checkInfo.getPriceOfUnit()) : info.getPriceOfUnit();
    }

    public int getUserLimit() {
        return !info.isValid() ? (null == checkInfo ? 0 : checkInfo.getUserLimit()) : info.getUserLimit();
    }

    public List<MoviePriceChange> getPriceChanges() {
        return !info.isValid() ? null : info.getPriceChanges();
    }

    public List<MovieStatusChange> getStatusChanges() {
        return !info.isValid() ? null : info.getStatusChanges();
    }
}
